home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / System / PPCReleaseDEV / Docs / PowerOpenAPI.txt next >
Encoding:
Text File  |  1998-02-21  |  12.7 KB  |  339 lines

  1. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2. !!!!!!!!!!!!!!!!!! We're using System V4 EABI !!!!!!!!!!!!!!!!!!!!!!
  3. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4.  
  5.  
  6. Here is a quick summary of the three main ABI's (AIX, NT, and V.4/eabi) for the
  7. PowerPC:
  8.  
  9. This document describes the differences between the (AIX based) PowerOpen
  10. Application Binary Interface for 32-bit big endian systems dated June 30th,
  11. 1994, the March 1995 draft of the System V Application Binary Interface
  12. PowerPC Processor Supplement calling sequences, and the Windows NT little
  13. PowerPC calling sequences.
  14.  
  15. 1. PowerOpen ABI
  16. ----------------
  17.  
  18.    The PowerOpen stack frame looks like:
  19.  
  20.     SP---->    +---------------------------------------+
  21.         | back chain to caller            | 0
  22.         +---------------------------------------+
  23.         | saved CR                | 4
  24.         +---------------------------------------+
  25.         | saved LR                | 8
  26.         +---------------------------------------+
  27.         | reserved for compilers        | 12
  28.         +---------------------------------------+
  29.         | reserved for binders            | 16
  30.         +---------------------------------------+
  31.         | saved TOC pointer            | 20
  32.         +---------------------------------------+
  33.         | Parameter save area (P)        | 24
  34.         +---------------------------------------+
  35.         | Alloca space (A)            | 24+P
  36.         +---------------------------------------+
  37.         | Local variable space (L)        | 24+P+A
  38.         +---------------------------------------+
  39.         | Save area for GP registers (G)    | 24+P+A+L
  40.         +---------------------------------------+
  41.         | Save area for FP registers (F)    | 24+P+A+L+G
  42.         +---------------------------------------+
  43.     old SP->| back chain to caller's caller        |
  44.         +---------------------------------------+
  45.  
  46.    The registers are used as follows (volatile means that a function does not
  47. have to preserve its value when it returns, saved means that a function must
  48. restore its value before returnning):
  49.  
  50.     r0        volatile, may be used by function linkage
  51.     r1        stack pointer
  52.     r2        table of contents register
  53.     r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  54.     r5  .. r10    volatile, pass 3rd - 8th int args
  55.     r11        volatile, pass static chain if language needs it
  56.     r12        volatile, used by dyn linker, exception handling
  57.     r13 .. r31    saved
  58.     f0        volatile
  59.     f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  60.     f5  .. f13    volatile, pass 5th - 13th float args
  61.     f14 .. f31    saved
  62.     lr        volatile, return address
  63.     ctr        volatile
  64.     xer        volatile
  65.     fpscr    volatile
  66.     cr0 .. cr1    volatile
  67.     cr2 .. cr4    saved
  68.     cr5 .. cr7    volatile
  69.  
  70.    When alloca is executed, the back chain to the caller's stack frame must be
  71. updated.
  72.  
  73.    The parameter save area includes 8 words so that r3..r10 can be saved there.
  74. In addition, calls to non-prototyped functions, and prototyped variable
  75. argument functions, must pass floating point arguments in both the floating
  76. point registers and either in the general registers or on the stack like the
  77. integer arguments are passed.  Structures are treated as integers for the
  78. purposes of calls.
  79.  
  80.    Variable argument functions store registers that aren't used by fixed
  81. arguments into the appropriate words of the parameter save area.  The va_list
  82. type is a char *.
  83.  
  84.    Function descriptors are used that are three words, containing the real
  85. address of the function, the function's TOC value, and the function's static
  86. link.  Function pointers actually point to the function descriptor, rather than
  87. the real function.  The function descriptor takes on the function name in the
  88. object file, and the real function name is prefixed by a period (".").  The
  89. calling sequence used by GCC 2.7.0 for V.4/eabi did not use function
  90. descriptors, unlike AIX and PowerOpen.
  91.  
  92.  
  93. 2.  V.4 ABI
  94. -----------
  95.  
  96.    The proposed System V.4 ABI stack frame looks like:
  97.  
  98.     SP---->    +---------------------------------------+
  99.         | back chain to caller            | 0
  100.         +---------------------------------------+
  101.         | saved LR                | 4
  102.         +---------------------------------------+
  103.         | Parameter save area (P)        | 8
  104.         +---------------------------------------+
  105.         | Alloca space (A)            | 8+P
  106.         +---------------------------------------+
  107.         | Local variable space (L)        | 8+P+A
  108.         +---------------------------------------+
  109.         | saved CR (C)                | 8+P+A+L
  110.         +---------------------------------------+
  111.         | Save area for GP registers (G)    | 8+P+A+L+C
  112.         +---------------------------------------+
  113.         | Save area for FP registers (F)    | 8+P+A+L+C+G
  114.         +---------------------------------------+
  115.     old SP->| back chain to caller's caller        |
  116.         +---------------------------------------+
  117.  
  118.    The registers are used as follows (volatile means that a function does not
  119. have to preserve its value when it returns, saved means that a function must
  120. restore its value before returnning):
  121.  
  122.     r0        volatile, may be used by function linkage
  123.     r1        stack pointer
  124.     r2        reserved for system
  125.     r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  126.     r5  .. r10    volatile, pass 3rd - 8th int args
  127.     r11    .. r12    volatile, may be used by function linkage
  128.     r13        small data area pointer
  129.     r14 .. r31    saved
  130.     f0        volatile
  131.     f1        volatile, pass 1st float arg, return 1st float
  132.     f2  .. f8    volatile, pass 2nd - 8th float args
  133.     f9  .. f13    volatile
  134.     f14 .. f30    saved
  135.     f31        saved, static chain if needed.
  136.     lr        volatile, return address
  137.     ctr        volatile
  138.     xer        volatile
  139.     fpscr    volatile*
  140.     cr0        volatile
  141.     cr1        volatile**
  142.     cr2 .. cr4    saved
  143.     cr5 .. cr7    volatile
  144.  
  145. * The VE, OE, UE, ZE, XE, NI, and RN (rounding mode) bits of the FPSCR may be
  146. changed only by a called function such as fpsetround that has the documented
  147. effect of changing them, the rest of the FPSCR is volatile.
  148.  
  149. ** Bit 6 of the CR (CR1 floating point invalid exception bit) is set to 1 if a
  150. variable argument function is passed floating point arguments in registers.
  151.  
  152.    When alloca is executed, the back chain to the caller's stack frame and the
  153. link register save area must be updated.
  154.  
  155.    The parameter save area does not contain space to store the 8 integer
  156. arguments.  If it is desired that they be stored, the callee must allocate
  157. space to save it in the local variable area of the stack.  Structures and
  158. unions are copied into temporary slots and an address of the temporary slot is
  159. passed as the argument.
  160.  
  161.    Variable argument functions must store the registers used for passing
  162. arguments that aren't used for fixed arguments into a 96 word area on the stack
  163. in the local variable section.  If bit 6 of the CR is not 1, it doesn't have to
  164. save the floating point registers.  The va_list type is defined as follows:
  165.  
  166.     typedef struct {
  167.         char gpr;            /* index to next saved gp register */
  168.         char fpr;            /* index to next saved fp register */
  169.         char *overflow_arg_area;    /* ptr to next overflow argument */
  170.         char *reg_save_area;    /* ptr to reg save area */
  171.     } va_list[1];
  172.  
  173.  
  174. 3. Windows NT
  175. -------------
  176.  
  177.    The Windows NT stack frame looks like:
  178.  
  179.     SP---->    +---------------------------------------+
  180.         | back chain to caller            | 0
  181.         +---------------------------------------+
  182.         | reserved                | 4
  183.         +---------------------------------------+
  184.         | saved TOC pointer            | 8
  185.         +---------------------------------------+
  186.         | reserved                | 12
  187.         +---------------------------------------+
  188.         | reserved                | 16
  189.         +---------------------------------------+
  190.         | reserved                | 20
  191.         +---------------------------------------+
  192.         | Parameter save area (P)        | 24
  193.         +---------------------------------------+
  194.         | Alloca space (A)            | 24+P
  195.         +---------------------------------------+
  196.         | Local variable space (L)        | 24+P+A
  197.         +---------------------------------------+
  198.         | Save area for CR (C)            | 24+P+A+L
  199.         +---------------------------------------+
  200.         | Save area for LR (R)            | 24+P+A+L+C
  201.         +---------------------------------------+
  202.         | Save area for GP registers (G)    | 24+P+A+L+C+R
  203.         +---------------------------------------+
  204.         | Save area for FP registers (F)    | 24+P+A+L+C+R+G
  205.         +---------------------------------------+
  206.     old SP->| back chain to caller's caller        |
  207.         +---------------------------------------+
  208.  
  209.    The registers are used as follows (volatile means that a function does not
  210. have to preserve its value when it returns, saved means that a function must
  211. restore its value before returnning):
  212.  
  213.     r0        volatile, may be used by function linkage
  214.     r1        stack pointer
  215.     r2        table of contents register
  216.     r3    .. r4    volatile, pass 1st - 2nd int args, return 1st - 2nd ints
  217.     r5  .. r10    volatile, pass 3rd - 8th int args
  218.     r11        volatile, pass static chain if language needs it
  219.     r12        volatile, used by dyn linker, exception handling
  220.     r13        reserved for use by the OS
  221.     r14 .. r31    saved
  222.     f0        volatile
  223.     f1  .. f4    volatile, pass 1st - 4th float args, return 1st - 4th floats
  224.     f5  .. f13    volatile, pass 5th - 13th float args
  225.     f14 .. f31    saved
  226.     lr        volatile, return address
  227.     ctr        volatile
  228.     xer        volatile
  229.     fpscr    volatile
  230.     cr0 .. cr1    volatile
  231.     cr2 .. cr4    saved
  232.     cr5 .. cr7    volatile
  233.  
  234.    When alloca is executed, the back chain to the caller's stack frame must be
  235. updated.
  236.  
  237.    The parameter save area includes 8 words so that r3..r10 can be saved there.
  238. In addition, calls to non-prototyped functions, and prototyped variable
  239. argument functions, must pass floating point arguments in both the floating
  240. point registers and either in the general registers or on the stack like the
  241. integer arguments are passed.  Structures are treated as integers for the
  242. purposes of calls.
  243.  
  244.    Variable argument functions store registers that aren't used by fixed
  245. arguments into the appropriate words of the parameter save area.  The va_list
  246. type is a char *.
  247.  
  248.    Function descriptors are used that are two words, containing the real
  249. address of the function, and the function's TOC value.  Function pointers
  250. actually point to the function descriptor, rather than the real function.  The
  251. function descriptor takes on the function name in the object file, and the real
  252. function name is prefixed by a two periods ("..").
  253.  
  254.  
  255.  
  256. 4. Differences between the calling sequences:
  257. ---------------------------------------------
  258.  
  259.    The following differences exist between the three calling sequences:
  260.  
  261.     1)  Only 8 floating point args are passed in registers in V.4 compared to
  262.     13 in PowerOpen and NT.  Also under V.4, floating arguments passed in
  263.     floating registers don't cause the corresponding integer registers to
  264.     be skipped.
  265.  
  266.     2)    V.4 has no register save area for the 8 words passed in GP registers.
  267.  
  268.     3)    Varargs/stdarg support is completely different between the V.4 and
  269.     PowerOpen/NT.  In particular, PowerOpen/NT passes floating args in both
  270.     integer and floating registers, and uses the register save area to make
  271.     one contiguous area.  The va_list type is a char *.  V.4 never passes
  272.     floating arguments in integer registers.  The registers used to hold
  273.     arguments are saved in a separate save area, and va_list is an array of
  274.     1 element of a structure that contains pointers to the stack and
  275.     register save area, and two char variables indicating how many integer
  276.     and floating point registers have been processed.  In addition, bit 6
  277.     of the condition code register is set to 1 if floating point arguments
  278.     were passed, and 0 if they were not.
  279.  
  280.     4)    V.4 doesn't support a TOC register, but the register is reserved for
  281.     system use.
  282.  
  283.     5)    V.4 uses r13 to point to the small data area, while PowerOpen uses it
  284.     as a normal caller save register, and NT reserves it for use by the
  285.     operating system.
  286.  
  287.     6)    Where the LR/CR is stored on the stack is different in all three.
  288.  
  289.     7)    The static chain (environment pointer) is in r31 for V.4 and r11 for
  290.     PowerOpen.  NT doesn't have a defined register for passing the static
  291.     chain, so GCC uses r11.
  292.  
  293.     8)    Under PowerOpen/NT, structures and unions are passed in registers or on
  294.     the stack like large integers, while V.4 copies them to a temporary
  295.     location and passes the pointer to that location.
  296.  
  297.     9)    A long long passed as word 7 is not split between the stack and the
  298.     register under V.4.
  299.  
  300.    10)    Alloca for V.4 must copy both the stack back chain and the return
  301.     address when extending the stack, while PowerOpen only copies the stack
  302.     back chain.
  303.  
  304.    11)    PowerOpen and NT use function descriptors, and function pointers point
  305.     to the function descriptor.  The real function name is prefixed by one
  306.     or two periods.  V.4 (and GCC 2.7.0 for V.4/eabi which otherwise used
  307.     the AIX calling sequence) has function pointers point to the actual
  308.     function (which is not prefixed).
  309.  
  310. For example, consider the following example:
  311.  
  312.     struct word { int a; } st;
  313.     int i1, i2;
  314.     double d1, d2;
  315.     extern void bar (int, double, struct word, ...);
  316.  
  317.     void foo (void) {
  318.         bar (i1, d1, st, i2, d2);
  319.     }
  320.  
  321. PowerOpen and NT would call bar as follows:
  322.  
  323.     r3 <- i1
  324.     r6 <- st
  325.     r7 <- i2
  326.     r8 <- d2 word 1
  327.     r9 <- d2 word 2
  328.     f1 <- d1
  329.  
  330. V.4 would call bar as follows:
  331.  
  332.     <temp> <- copy of st
  333.     r3 <- i1
  334.     r4 <- address of <temp>
  335.     r5 <- i2
  336.     f1 <- d1
  337.     f2 <- d2
  338.     CR <- bit 6 set to 1
  339.